<?php

declare(strict_types=1);

namespace App\Model\Setting;

use Hyperf\DbConnection\Model\Model;

/**
 *  配置 - 用户专访
 */
class SettingUserQuestion extends Model
{
    protected $table = 'setting_user_question';
    protected $fillable = ['question', 'answer', 'gender'];

    static function getList($gender = -1)
    {
        $data = self::where(['flag' => 1])->whereIn('gender', [-1, $gender])->get()->toArray();
        $ret = [];
        foreach ($data as $item) {
            $ret[] = [
                'question_id' => $item['id'],
                'question' => $item['question'],
            ];
        }
        return $ret;
    }

    static function getTotalNum($gender = 0)
    {
        return self::where('flag', 1)->whereIn('gender', [-1, $gender])->count();
    }

    static function getQuestionIds($gender = 0)
    {
        return self::where('flag', 1)->whereIn('gender', [-1, $gender])->pluck('id')->toArray();
    }
}
